<template>
  <el-form ref="form">
    <!--<div style="float: left;font-size: 18px;width: 100%;text-align: left;margin-bottom: 15px;">行业归属</div>-->
    <el-form-item>
      <div v-for="(item,index) in form" style="float: left;width: 100%;text-align: left">
        <div style="font-size: 16px;text-align: left;margin-left: 30px;width:78%;display: inline">一级行业归属</div>
        <el-input v-model="item.oneLevel" placeholder="单行输入"></el-input>
        <el-button type="primary"  v-if="index==0" style="margin-left:20px;" @click="addOne()">添 加</el-button>
        <el-button type="danger"   v-else style="margin-left:20px;" @click="delOne(index)">删 除</el-button>
        <div style="width: 100%;height:5px;margin:5px 0"></div>
        
        <div style="font-size: 14px;text-align: left;margin-left: 90px;width:78%;display: inline">二级行业归属</div>
        <div v-for="(item2,index2) in item.twolevel" style="width: 100%;display: inline">
          <el-input v-model="item2.twoLevel" placeholder="单行输入" style="width:150px;"></el-input>
          <el-button type="primary"  v-if="index2==0" style="" @click="addOne2(index,index2)">✚</el-button>
          <el-button type="danger"   v-else style="margin:0 10px;" @click="delOne2(index,index2)">—</el-button>
        </div>

        <div style="width: 100%;height:10px;margin-bottom:30px"></div>
      </div>

    </el-form-item>

    <el-divider></el-divider>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">提交</el-button>
    </el-form-item>

  </el-form>
</template>

<script>
import { EventBus } 	 from 	"bus/mybus.js";
import {getHyData, doHyUpdate} from "../../crm/system/custom";

export default {
  name: "CustomHy",
  data(){
    return {
      form: {},
    }
  },
  created(){
    this.getRequestData()
  },

  methods:{
    getRequestData(){
      const payload       = {}
      payload.operatorId  = this.$store.state.operatorId
      getHyData(payload).then(res=>{
        console.log(res)
        this.form = res.content
      }).catch(err=>{
        EventBus.$emit('closeloading')
      })


    },


    //新增管理区域..
    addOne(){
      this.form.push({oneLevel:'',twolevel:[{}]})
    },
    //删除管理区域..
    delOne(index){
      this.form.splice(index,1)
    },

    addOne2(index,index2){
      this.form[index].twolevel.push({})
    },
    //删除管理区域..
    delOne2(index,index2){
      this.form[index].twolevel.splice(index2,1)
    },

    //提交
    onSubmit(){

      this.$confirm('确认提交操作??', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const payload       = {}
        payload.operatorId  = this.$store.state.operatorId
        payload.content        = this.form

        doHyUpdate(payload).then(res=>{
          this.$message.success('操作成功')
        }).catch(err=>{
          EventBus.$emit('closeloading')
        })
      }).catch(() => {});

    }

  },

}
</script>

<style scoped>
.el-select:hover {
  border-color: #C0C4CC;
  /* margin-right: 10px; */
}

.el-input{
  width:15%;
  margin-left: 20px;
  margin-bottom: 6px;
}

</style>